package com.khyr.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.khyr.dao.DictDataDao;
import com.khyr.entity.DictData;
import com.khyr.service.DictDataService;
import com.khyr.vo.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author 宋一恒
 * @version 1.0
 */
@Service
public class DictDataServiceImpl implements DictDataService {
    @Autowired
    private DictDataDao dictDataDao;

    @Autowired
    private RedisTemplate redisTemplate;
    @Override
    public R<List<DictData>> getDictDataByType(String dictType) {
        Object o = redisTemplate.opsForValue().get("dictData::" + dictType);
        if (o != null) {
            return new R<>(200,"查询成功",(List<DictData>) o);
        }
        QueryWrapper<DictData> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("dict_type",dictType);
        queryWrapper.eq("status","0");
        List<DictData> dictData = dictDataDao.selectList(queryWrapper);
        redisTemplate.opsForValue().set("dictData::" + dictType,dictData);
        return new R<>(200,"查询成功",dictData);
    }
}
